<?php
namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Session;
use think\Cookie;
use think\DB;

class Test extends Controller
{
    public function test(){
    	dump($_POST);
    }

    public function ajaxTest(){
    	$info = $_POST;
    	if($info)
    	{
    		return $this->success($info);
    	} else {
    		return $this->error(11);
    	}
    }

    public function dirtest($thedir) {
        $a=array();
        if (is_dir ($thedir)){
          $scanarray = scandir ($thedir);
          $count = count ($scanarray);
          for ($i = 0; $i < $count; $i++){
            if ($scanarray[$i] != "." && $scanarray[$i] != ".."){
              if (is_file ($thedir . "/" . $scanarray[$i])){
                $a['file'][] =  $scanarray[$i];
              }
              else $a['dir'][$scanarray[$i]] =  $this->dirtest($thedir.'/'.$scanarray[$i]);
            }
          }
        } else {
          return "Sorry, this directory does not exist.";
        }
        return $a;
      }
      public function tt()
      {
        dump(self::getFiles('../../fileManager', true, true));
      }

      public static function getFiles($directory, $mode1 = false, $mode2 = false) {
        if (!is_dir($directory)) {
            return false;
        }
        if ($mode1) {
            $files = array();
            if ($mode2) {
                $files['dir']['.'] = '';
                $files['dir']['..'] = '';
            }
            $scanarray = scandir($directory);
            $count = count($scanarray);
            $i = 0;
            for ($i; $i < $count; $i++) { 
                if ($scanarray[$i] != '.' && $scanarray[$i] != '..') {
                    $path = $directory . '/' . $scanarray[$i];
                    if (is_file($path)) {
                        $files['file'][] =  $scanarray[$i];
                    }
                    elseif (is_dir($path)) {
                        $files['dir'][$scanarray[$i]] = self::getFiles($path, $mode1, $mode2);
                    }
                }
            }
            return $files;
        } else {
            return scandir($directory);
        }
        
    }
}


